package edu.scau.divineplace.controller;

import edu.scau.divineplace.config.global.log.WebLog;
import edu.scau.divineplace.service.LikeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @Author: x1aolone
 * @Date: 2020/12/8 12:55
 */
@Slf4j
@RestController
@CrossOrigin
@Api("Like控制器")
@WebLog("Like控制器")
@Validated
@RequestMapping("/like")
public class LikeController {

    @Autowired
    private LikeService likeService;

    @ApiOperation("通过用户id、点赞内容id、点赞内容类型, 判断用户是否点赞内容")
    @GetMapping("/judge")
    public Boolean judge(@NotNull Long userId,@NotNull Long likeTargetId,@NotNull Integer likeTargetType){
        return likeService.judge(userId, likeTargetId, likeTargetType);
    }

    @ApiOperation("点赞内容，未测试")
    @PostMapping("")
    public void like (@NotNull Long userId, @NotNull Long likeTargetUserId,
                      @NotNull Integer likeTargetType, @NotNull Long likeTargetId) {
        // 用枚举接受参数，等下再弄
        likeService.like(userId, likeTargetUserId, likeTargetType, likeTargetId);
    }

    @ApiOperation("取消点赞，未测试")
    @DeleteMapping("")
    public void unlike (@NotNull Long userId, @NotNull Long likeTargetId, @NotNull Integer likeTargetType) {
        // 用枚举接受参数，等下再弄
        likeService.unlike(userId, likeTargetId, likeTargetType);
    }

}
